class SkillController < ApplicationController

  # Everything is only available to logged in volcom users
  before_filter :protect
  before_filter :protect_for_volcom
  
  def list
    @display_columns = Skill.content_columns.select { |c| c.name =~ /(skillname)/i }
    @display_data = Skill.display_list(params[:page])
  end

  def new
    @skill = Skill.new
  end

  def create
    @skill = Skill.new(params[:skill])
    if get_user.is_volcom && @skill.save
      flash[:notice] = 'Skill was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @skill = Skill.find(params[:id])
  end

  def update
    @skill = Skill.find(params[:id])
    if @skill && (get_user.is_otw || get_user.is_volcom)
      if @skill.update_attributes(params[:skill]) && update_skills(@skill)
        flash[:notice] = 'Skill was successfully updated.'
        redirect_to :action => 'show', :id => @skill
      else
        render :action => 'edit'
      end
    end
  end

  def destroy
    @skill = Skill.find(params[:id])
    if @skill && get_user.is_volcom
      @skill.destroy
      redirect_to :action => 'list'
    else
      flash[:error] = 'You may not delete skills.'
    end
  end

end
